function [Dist]=distance(car_route,d,K)
NN=length(car_route);
Dist=zeros(1,K);
for i=1:NN
    if ~isempty(car_route{i})
        for j=1:length(car_route{i})
            if j==1
                Dist(i)=Dist(i)+d(car_route{i}(j)+1,1);
            else
                Dist(i)=Dist(i)+d(car_route{i}(j)+1,car_route{i}(j-1)+1);
            end
        end
    end
    if ~isempty(car_route{i})
        Dist(i)=Dist(i)+d(car_route{i}(end)+1,1);
    end
end
end